package com.duowei.diandan.callback;


import android.support.v7.util.DiffUtil;
import android.util.Log;

import com.duowei.diandan.bean.food.FoodItem;

import java.util.List;
import java.util.Objects;

public class FoodItemCallback extends DiffUtil.Callback {
    private static final String TAG = "FoodItemCallback";

    private final List<FoodItem> mOldList;
    private final List<FoodItem> mNewList;

    public FoodItemCallback(List<FoodItem> oldList, List<FoodItem> newList) {
        mOldList = oldList;
        mNewList = newList;
    }

    @Override
    public int getOldListSize() {
        return mOldList.size();
    }

    @Override
    public int getNewListSize() {
        return mNewList.size();
    }

    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        FoodItem oldItem = mOldList.get(oldItemPosition);
        FoodItem newItem = mNewList.get(newItemPosition);

        return Objects.equals(oldItem, newItem);
    }

    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        FoodItem oldItem = mOldList.get(oldItemPosition);
        FoodItem newItem = mNewList.get(newItemPosition);

        boolean result = Objects.equals(oldItem.getFood(), newItem.getFood());

        Log.d(TAG, "areContentsTheSame: oldItem = " + oldItem.getImgNo() + " " + oldItem.getName());
        Log.d(TAG, "areContentsTheSame: newItem = " + newItem.getImgNo() + " " + newItem.getName());
        Log.d(TAG, "areContentsTheSame: result = " + result);

        return result;
    }
}
